package com.example.lanouhn.bantangapp.activities.utils;


import com.example.lanouhn.bantangapp.activities.contants.Deliciousfood;
import com.example.lanouhn.bantangapp.activities.contants.Gift;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 解析Json数据
 */
public class JsonUtils_Deliciousfood {

    /**
     * @param json json字符串
     * @return 美食
     */
    public static List<Deliciousfood> getfoodList(String json) {
        List<Deliciousfood> list = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(json);

            JSONObject jsonObject1= jsonObject.getJSONObject("data");
            JSONArray jsonArray = jsonObject1.getJSONArray("topic");

            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject j = jsonArray.getJSONObject(i);


                Deliciousfood m = new Deliciousfood();
                m.setTitle(j.getString("title"));
                m.setLikes(j.getString("likes"));
                m.setPic(j.getString("pic"));
                m.setComments(j.getString("comments"));
                m.setUser(j.getJSONObject("user"));
                JSONObject s =  m.getUser();
               m.setNickname( s.getString("nickname"));

                list.add(m);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
